import { _decorator, Color, Component, Label, Node, RichText, Sprite, SpriteFrame } from 'cc';
import { Soldier } from '../entity/Soldier';
import { Advanced } from '../entity/Advanced';
import { Building } from '../entity/Buildings';


const { ccclass, property } = _decorator;

@ccclass('DevelopMaxLevelBlock')
export class DevelopMaxLevelBlock extends Component {
    @property(Sprite)
    cover: Sprite
    @property(Label)
    tittle: Label
    @property(Label)
    condition: Label
    
    @property(Label)
    attack: Label
    @property(Label)
    level: Label
   
    @property(Label)
    typeName: Label

    @property(SpriteFrame)
    attackImg:SpriteFrame
    @property(SpriteFrame)
    defenseImg:SpriteFrame

    private advanced: Advanced
    private building: Building

    private offTime: number = 0
    start() {
      
    }

    /**
     * 设置攻击等级的数据
     * @param soldier 
     */
    setDataAttack(soldier: Soldier) {
        this.advanced = soldier.getAttackAdvanced()
        this.building = this.advanced.building
        this.tittle.string = '攻击强化'
        this.typeName.string = '攻击力'
        this.cover.spriteFrame = this.attackImg

        this.setData()
    }

    /**
     * 设置防御等级的数据
     * @param soldier 
     */
    setDataDefense(soldier: Soldier) {
        this.advanced = soldier.getDefenseAdvanced()
        this.building = this.advanced.building
        this.tittle.string = '防御强化'
        this.typeName.string = '防御力'
        this.cover.spriteFrame = this.defenseImg

        this.setData()



    }

    setData() {
        let soldier = this.advanced.soldier
        let building = this.advanced.building
        this.condition.string = `${building.name}${building.level}级`
        this.level.string = this.advanced.level + ''
        
        this.attack.string = '+' + Math.floor(this.advanced.addition * 1000) / 10  + '%'
    }

}


